close;
clc;
clear;
%%%%%%%%%%%%%
iMaxwell = actxserver('Ansoft.ElectronicsDesktop');
oDesktop = iMaxwell.GetAppDesktop();
oDesktop.RestoreWindow();
oProject = oDesktop.NewProject;
oProject.SaveAs('G:\\temp\\Prj_tmp\\maxwell_secondary_development\\tmp.aedt', true);
oProject.InsertDesign("Maxwell 2D", "Maxwell2DDesign1", "Electrostatic", "");
oDesign = oProject.SetActiveDesign("Maxwell2DDesign1");
oEditor = oDesign.SetActiveEditor("3D Modeler");
oEditor.CreateCircle(...
	{
		"NAME:CircleParameters",...
		"IsCovered:="		, true,...
		"XCenter:="		, "0mm",...
		"YCenter:="		, "0mm",...
		"ZCenter:="		, "0mm",...
		"Radius:="		, "5mm",...
		"WhichAxis:="		, "Z",...
		"NumSegments:="		, "0"...
	}, ...
	{
		"NAME:Attributes",...
		"Name:="		, "Circle1",...
		"Flags:="		, "",...
		"Color:="		, "(143 175 143)",...
		"Transparency:="	, 0,...
		"PartCoordinateSystem:=", "Global",...
		"UDMId:="		, "",...
		"MaterialValue:="	, '"vacuum"',...
		"SurfaceMaterialValue:=", '""',...
		"SolveInside:="		, true,...
		"ShellElement:="	, false,...
		"ShellElementThickness:=", "0mm",...
		"IsMaterialEditable:="	, true,...
		"UseMaterialAppearance:=", false,...
		"IsLightweight:="	, false
	});
oEditor.CreateCircle(...
	{
		"NAME:CircleParameters",...
		"IsCovered:="		, true,...
		"XCenter:="		, "0mm",...
		"YCenter:="		, "0mm",...
		"ZCenter:="		, "0mm",...
		"Radius:="		, "3mm",...
		"WhichAxis:="		, "Z",...
		"NumSegments:="		, "0"...
	}, ...
	{
		"NAME:Attributes",...
		"Name:="		, "Circle2",...
		"Flags:="		, "",...
		"Color:="		, "(143 175 143)",...
		"Transparency:="	, 0,...
		"PartCoordinateSystem:=", "Global",...
		"UDMId:="		, "",...
		"MaterialValue:="	, '"vacuum"',...
		"SurfaceMaterialValue:=", '""',...
		"SolveInside:="		, true,...
		"ShellElement:="	, false,...
		"ShellElementThickness:=", "0mm",...
		"IsMaterialEditable:="	, true,...
		"UseMaterialAppearance:=", false,...
		"IsLightweight:="	, false
	});
oEditor.Subtract( ...
	{
		"NAME:Selections",...
		"Blank Parts:="		, "Circle1",...
		"Tool Parts:="		, "Circle2"...
	}, ...
	{
		"NAME:SubtractParameters",...
		"KeepOriginals:="	, true...
	});
oModule = oDesign.GetModule("BoundarySetup");
oModule.AssignVoltage( ...
    {
		"NAME:Voltage1",...
		"Edges:="		, {13},...
		"Value:="		, "1V",...
		"CoordinateSystem:="	, ""
	});
oModule.AssignVoltage(...
	{
		"NAME:Voltage2",...
		"Edges:="		, {7},...
		"Value:="		, "0V",...
		"CoordinateSystem:="	, ""...
	});
oModule = oDesign.GetModule("AnalysisSetup");
oModule.InsertSetup("Electrostatic",...
	{
		"NAME:Setup1",...
		"Enabled:="		, true,...
		{
			"NAME:MeshLink",...
			"ImportMesh:="		, false
		},...
		"MaximumPasses:="	, 10,...
		"MinimumPasses:="	, 2,...
		"MinimumConvergedPasses:=", 1,...
		"PercentRefinement:="	, 30,...
		"SolveFieldOnly:="	, false,...
		"PercentError:="	, 1,...
		"SolveMatrixAtLast:="	, true,...
		"UseNonLinearIterNum:="	, false,...
		"NonLinearResidual:="	, 0.001
	});
oDesign.AnalyzeAll();
oModule = oDesign.GetModule("FieldsReporter");
oModule.CreateFieldPlot(...
	{
		"NAME:Voltage1",...
		"SolutionName:="	, "Setup1 : LastAdaptive",...
		"UserSpecifyName:="	, 0,...
		"UserSpecifyFolder:="	, 0,...
		"QuantityName:="	, "Voltage",...
		"PlotFolder:="		, "Voltage",...
		"StreamlinePlot:="	, false,...
		"AdjacentSidePlot:="	, false,...
		"FullModelPlot:="	, false,...
		"IntrinsicVar:="	, "",...
		"PlotGeomInfo:="	, {1,"Surface","FacesList",2,"6","12"},...
		"FilterBoxes:="		, {0},...
		{
			"NAME:PlotOnSurfaceSettings",...
			"Filled:="		, false,...
			"IsoValType:="		, "Tone",...
			"AddGrid:="		, false,...
			"MapTransparency:="	, true,...
			"Refinement:="		, 0,...
			"Transparency:="	, 0,...
			"SmoothingLevel:="	, 0,...
			"ShadingType:="		, 0,...
			{
				"NAME:Arrow3DSpacingSettings",...
				"ArrowUniform:="	, true,...
				"ArrowSpacing:="	, 0,...
				"MinArrowSpacing:="	, 0,...
				"MaxArrowSpacing:="	, 0
			},...
			"GridColor:="		, {255,255,255}
		},...
		"EnableGaussianSmoothing:=", false,...
		"SurfaceOnly:="		, false
	}, "Field");
oProject.Save();
delete(iMaxwell);
 